/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.adsi.persistencia;

import com.adsi.modelo.Clientes;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Estudiante
 */
@Stateless
public class ClienteDAO implements IClienteDAO {

    @PersistenceContext
    private EntityManager entityManager;

    @Override
    public void registrar(Clientes clientes) {
        try{
        entityManager.persist(clientes);
        }catch(RuntimeException e){
            throw e;
        }
    }

    @Override
    public void modificar(Clientes clientes) {
        try{
        entityManager.merge(clientes);
        }catch(RuntimeException e){
            throw e;
        }
    }

    @Override
    public void eliminar(Clientes clientes) {
        try{
        entityManager.remove(clientes);
        }catch(RuntimeException e){
            throw e;
        }
    }

    @Override
    public List<Clientes> consultar() {
        try{
            String jpql="select c from Clientes c";
            Query query=entityManager.createQuery(jpql);
            return query.getResultList();
        }catch(RuntimeException e){
            throw e;
        }
    }

    @Override
    public Clientes consultarPorCod(Long cli_cedula) {
        try{
            return entityManager.find(Clientes.class, cli_cedula);
        }catch(RuntimeException e){
            throw e;
        }
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
}
